/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司 保留所有权利。
 */
package com.jiashihui.schema_lgorithm.java.socket.service2;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    private static final int NUM_1024 = 1024;
    private static final int NUM_4 = 4;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // ChannelPipeline 类似于一个拦截器链
        // ChannelPipeline ： 可以看做是ChannelHandler的链表，用来添加不同的ChannelHandler
        ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(NUM_1024 * NUM_1024 * NUM_1024, 0, NUM_4, 0, 0));
        // 对于web请求进行编解码作用
        ch.pipeline().addLast(new MessageDecoder());
        ch.pipeline().addLast(new ServerHandler());
    }
}
